package com.noble.glamour.module.local.chat.utils;

import com.noble.glamour.module.logic.application.ModuleMgr;
import com.noble.library.log.PToast;
import com.noble.library.observe.MsgMgr;
import com.noble.meether.chat.MessageConstant;
import com.noble.meether.chat.unread.UnreadMgrImpl;

/**
 * 消息处理工具类
 */
public class MsgUtils {

    /**
     * 是否是需要保存消息
     */
    public static boolean isSaveMsg(int msgType) {
        return msgType == MessageConstant.MSG_ID_TEXT ||
                msgType == MessageConstant.MSG_ID_PIC ||
                msgType == MessageConstant.MSG_ID_VIDEO ||
                msgType == MessageConstant.MSG_ID_GIFT;
    }

    /**
     * 系统公告未读消息 + addNum
     */
    public static void handleNoticeUnread(int addNum) {
        ModuleMgr.getUnreadMgr().addNumUnread(UnreadMgrImpl.SYS_NOTICE, addNum);
    }

    /**
     * 移除系统公告未读消息
     */
    public static void removeNoticeUnread() {
        ModuleMgr.getUnreadMgr().resetUnreadByKey(UnreadMgrImpl.SYS_NOTICE);
    }

    /**
     * 具体某用户未读消息 + 1
     */
    public static void handleSbUnread(long fromId) {
        ModuleMgr.getUnreadMgr().addNumUnread(UnreadMgrImpl.MSG_NOTICE);  // 二级 与 一级 角标 + 1
        ModuleMgr.getUnreadMgr().addMsgNumUnread(fromId);   // 具体用户未读 + 1
    }

    /**
     * 处理申请好友消息 + addNum
     *
     * @param isReset 是否重置个人资料中未读数
     */
    public static void handleAskFriend(int addNum, boolean isReset) {
        ModuleMgr.getUnreadMgr().addNumUnread(UnreadMgrImpl.MY_FRIEND, addNum);
        ModuleMgr.getUnreadMgr().addMsgNumUnread(0, addNum);
        if (isReset)
            ModuleMgr.getCenterMgr().updateAskFriendUnread();  // 重置个人资料中未读数
    }

    public static void showToast(final String content) {
        MsgMgr.getInstance().runOnUiThread(() -> PToast.showShort(content));
    }
}
